﻿using System;

namespace Com.OpenCode.Framework.DevForm
{
    /// <summary>
    ///     自定义组合框列表项。
    /// </summary>
    public class OpenCodeComboBoxItem : IConvertible
    {
        private string _key;

        private object _keyOfValue;

        /// <summary>
        ///     构造<see cref="OpenCodeComboBoxItem" />的实例。
        /// </summary>
        /// <param name="key"></param>
        /// <param name="keyOfValue"></param>
        public OpenCodeComboBoxItem(string key, object keyOfValue)
        {
            _key = key;
            _keyOfValue = keyOfValue;
        }

        /// <summary>
        ///     项的显示值。
        /// </summary>
        public string Key
        {
            get { return _key; }
            set { _key = value; }
        }

        /// <summary>
        ///     项显示值的值。
        /// </summary>
        public object KeyOfValue
        {
            get { return _keyOfValue; }
            set { _keyOfValue = value; }
        }

        public TypeCode GetTypeCode()
        {
            return Convert.GetTypeCode(_keyOfValue);
        }

        public bool ToBoolean(IFormatProvider provider)
        {
            return Convert.ToBoolean(_keyOfValue, provider);
        }

        public byte ToByte(IFormatProvider provider)
        {
            return Convert.ToByte(_keyOfValue, provider);
        }

        public char ToChar(IFormatProvider provider)
        {
            return Convert.ToChar(_keyOfValue, provider);
        }

        public DateTime ToDateTime(IFormatProvider provider)
        {
            return Convert.ToDateTime(_keyOfValue, provider);
        }

        public decimal ToDecimal(IFormatProvider provider)
        {
            return Convert.ToDecimal(_keyOfValue, provider);
        }

        public double ToDouble(IFormatProvider provider)
        {
            return Convert.ToDouble(_keyOfValue, provider);
        }

        public short ToInt16(IFormatProvider provider)
        {
            return Convert.ToInt16(_keyOfValue, provider);
        }

        public int ToInt32(IFormatProvider provider)
        {
            return Convert.ToInt32(_keyOfValue, provider);
        }

        public long ToInt64(IFormatProvider provider)
        {
            return Convert.ToInt64(_keyOfValue, provider);
        }

        public sbyte ToSByte(IFormatProvider provider)
        {
            return Convert.ToSByte(_keyOfValue, provider);
        }

        public float ToSingle(IFormatProvider provider)
        {
            return Convert.ToSingle(_keyOfValue, provider);
        }

        public string ToString(IFormatProvider provider)
        {
            return _key;
            //return Convert.ToString(_keyOfValue, provider);
        }

        public object ToType(Type conversionType, IFormatProvider provider)
        {
            object value = Convert.ChangeType(_keyOfValue, conversionType, provider);
            return value;
        }

        public ushort ToUInt16(IFormatProvider provider)
        {
            return Convert.ToUInt16(_keyOfValue, provider);
        }

        public uint ToUInt32(IFormatProvider provider)
        {
            return Convert.ToUInt32(_keyOfValue, provider);
        }

        public ulong ToUInt64(IFormatProvider provider)
        {
            return Convert.ToUInt64(_keyOfValue, provider);
        }

        public override string ToString()
        {
            return _key;
        }
    }
}